﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinFormStoreControl
{
    public partial class CommodityCtrl : UserControl
    {

        private string goodsName;
        [Category("商品")]
        [Description("商品名称")]
        public string GoodsName 
        { 
            get { return goodsName; } 
            set {  goodsName=value; 
                this.lblName.Text = goodsName.ToString();
            }
        }
        private double price;
        [Category("商品")]
        [Description("商品价格")]
        public double Price
        {
            get { return price; }
            set { price = value; 
                this.lblPrice.Text ="￥"+price.ToString("F2");
            }
        }
        private int count;
        [Category("商品")]
        [Description("商品数量")]
        public int Count
        {
            
            get { return count; }
            set { count=value;
                this.lblStockNum.Text = "商品数量:" +count.ToString();
            }
        }
        private Image picture;
        [Category("商品")]
        [Description("商品视图")]
        public Image Picture
        {
            get { return picture; }
            set
            {
                picture = value;
                if (pictureBox != null && picture != null)
                {
                    pictureBox.Image = picture;
                }
                else
                {
                    pictureBox.BackColor=Color.Black;
                }
            }
        }
        
        public CommodityCtrl()
        {
            InitializeComponent();
            //TakeOff();
        }


        private void CommodityCtrl_Load(object sender, EventArgs e)
        {

        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            MessageBox.Show("点击可增加");
        }

        private void btnReducing_Click(object sender, EventArgs e)
        {
            MessageBox.Show("点击可减少");
        }

        private void btnCart_Click(object sender, EventArgs e)
        {

        }

        //private void TakeOff()
        //{
        //    int stockNum = int.Parse(this.lblStockNum.Text);
        //    if ( stockNum<= 0)
        //    {
        //        Panel panel = new Panel()
        //        {
        //            BackColor = Color.FromArgb(128, 255, 255,255),
        //            Size = new Size(340,200),
        //            Location = new Point(0,0),
        //            BorderStyle = BorderStyle.FixedSingle,

        //        };
        //        panel.BringToFront();
        //        Label label = new Label()
        //        {
        //            Text = "库存不足",
        //           ForeColor=Color.Red,
        //           TextAlign=ContentAlignment.MiddleCenter,
        //           Dock = DockStyle.Fill,
        //        };
        //        //label.BringToFront();
        //        panel.Controls.Add(label);
        //        this.Controls.Add(panel);
        //    }
        //}
    }
}
